//
//  UIKeyboardController.m
//  RunTime
//
//  Created by 宜必鑫科技 on 2017/11/8.
//  Copyright © 2017年 宜必鑫科技. All rights reserved.
//

#import "UIKeyboardController.h"

@interface UIKeyboardController ()<UITextFieldDelegate>
@property (nonatomic, strong) UITextField *textField;
@end

@implementation UIKeyboardController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    _textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    _textField.placeholder = @"请输入想要输入的东西";
    _textField.delegate = self;
    _textField.backgroundColor = [UIColor lightGrayColor];
    _textField.keyboardType = UIKeyboardTypeNumberPad;
    [self.view addSubview:_textField];
}
// 但是注意只有以下两种数字键盘才有效果：UIKeyboardTypeNumberPad，UIKeyboardTypePhonePad；
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    for (UIView *view in [UIApplication sharedApplication].windows)
    {
        [self findSubView:view];
    }
    return YES;
}


-(void)findSubView:(UIView*)view
{
    for (UIView* subView in view.subviews)
    {
        if([[NSString stringWithUTF8String:object_getClassName(subView)] isEqualToString:@"UIImageView"])
        {
            subView.backgroundColor = [UIColor redColor];
            return;
        }
        [self findSubView:subView];
    }
}




@end
